#include <cstdio>
#include <vector>
#include <set>

#define INF 2147483647

int _a[100005], a[200005], q[100005];

char r[20][100005];

int solve(int k){
    std::vector<int> v[20];

    for (int i=1; i<=(1<<k); ++i)
        v[k].push_back(i);
    
    for (int i=k-1, cnt=1; ~i; --i, ++cnt){
        for (int j=0; j<(1<<i); ++j)
            if (a[v[i+1][2*j+r[i][j]-'0']] >= cnt)
                v[i].push_back(v[i+1][2*j+r[i][j]-'0']);
            else
                v[i].push_back(v[i+1][2*j+!(r[i][j]-'0')]);
    }
    
    return v[0].front();
}

int main(){
    freopen("arena.in" , "r", stdin );
    freopen("arena.out", "w", stdout);

    int n, m, k;
    scanf("%d %d", &n, &m);

    for (int i=1; i<=n; ++i)
        scanf("%d", _a+i);
    
    for (int i=1; i<=m; ++i)
        scanf("%d", q+i);
    
    for (int i=20; ~i; --i)
        if ((1<<i) >= n)
            k = i;
    
    for (int i=k-1; ~i; --i)
        scanf("%s", r[i]);
    
    int t;
    scanf("%d", &t);

    while (t--){
        int x[5];

        for (int i=0; i<4; ++i)
            scanf("%d", x+i);
        
        for (int i=1; i<=n; ++i)
            _a[i] ^= x[i%4];
        
    }

    long long ans = 0;

    for (int i=1; i<=m; ++i){
        long long sum = 0;
        std::set<int> id;
        for (int j=20; ~j; --j)
            if ((1<<j) >= q[i])
                k = j;
        for (int j=1; j<=(1<<k); ++j)
            if (j <= q[i])
                a[j] = _a[j];
            else
                a[j] = 0;
        id.insert(solve(k));
        for (int j=q[i]+1; j<=(1<<k); ++j){
            a[j] = INF;
            id.insert(solve(k));
            a[j] = 0;
        }
        for (int j:id)
            sum += j;
        ans ^= (sum*i);
    }

    printf("%lld\n", ans);

    return 0;
}

